
<link href="{{ asset('/admins/css/bootstrap.min.css') }}" rel="stylesheet"> 
<!-- Button trigger modal -->
<html>
<head>
<title>Bootstrap 实例 - 模态框（Modal）插件</title>
<link href="{{ asset('/admins/css/bootstrap.min.css') }}" rel="stylesheet">
<script src="{{ asset('admins/js/jquery.min.js') }}"></script>
<script src="{{ asset('admins/js/bootstrap.min.js') }}"></script>
</head>
<body>
<center>
@if (session('msg'))
          <div class="alert alert-danger">
              <ul>
                  
          <li>{{ session('msg') }}</li>
                  
            </ul>
            </div>
        @endif
    
    @if (count($errors) > 0)
          <div class="alert alert-danger">
              <ul>
            @foreach ($errors->all() as $error)       
          <li>{{ $error }}</li>
             @endforeach      
            </ul>
            </div>
      @endif
    <form action="/admin/comment" method="get">
      商品品牌:<input type="text" name="name">
      <input type="submit" value="搜索">
      
    </form>
  <table class="table table-hover">
    <tr>
        <!-- <th>ID</th> -->
        <!-- <th>商品分类</th> -->
        
        <th>商品名称</th>
        <th>评论时间</th>
        <th>评论内容</th>
        <th>评分</th>
        <th>是否回复</th>
        <th>评论用户</th>
        <th>操作</th>
        
    </tr>
     @foreach( $list as $v)
    <tr>
  
      
      <td>{{ $v->name }}</td>
      <td>{{ date('Y-m-d H:i:s',$v->commentPubTime) }}</td>
      <td>{{ $v->commentBody }}</td>
      <td>{{ $v->commentStar }}</td>
      <td>{{ $v->commentStatu==0?'未回复':'已回复' }}</td>
      <td>{{ $v->userName  }}</td>
      <td><button type="button" id="mybutton" onclick="fun({{ $v->commentId }})" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal">详情</button>

      <a href="javascript:dodel({{ $v->commentId }})"><button type="button"  class="btn btn-primary btn-xs" data-toggle="modal">删除</button></a>
      </td>
    </tr>

    @endforeach
</table>
  {{ $list->appends($where)->links() }}
  <form action="" method="post" name="delform">
    {{ csrf_field() }}
    {{ method_field('delete') }}
  </form>
<script type="text/javascript">
        function dodel(id)
        {
           
            if (confirm('确定要删除吗?')) {
                var form = document.delform;
                form.action = '/admin/comment/'+id;
                form.submit();
            }
        }
    </script>


<!-- Button trigger modal -->
<!-- <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal">
 
</button> -->

<!-- <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>
 -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">回复详情</h4>
      </div>
      <div class="modal-body">
        
        <!--显示详情-->
        <table class="table table-bordered" >
          <tr>
            <th>回复内容</th>
            <th>回复时间</th>
            <th>回复人</th>
          </tr>
          <tbody id="content">
            
          </tbody>
          <!-- <p class="bg-primary" id="content"></p> -->

          
        </table>

          <!--回复条-->
        <form action="#" method="post" id="myform">
          {{ csrf_field() }}
          <input type="hidden" name="replayCid" id="rep" >
          <textarea class="form-control" rows="3" name="replayContent"></textarea>
         <button type="button" class="btn btn-default" id="butt" onclick="replay()">回复</button>

        </form>
        <script type="text/javascript">
        //回复
        function replay()
        {
           
           
                var form = document.getElementById('myform')
                form.action = '/admin/replay';
                form.submit();
            
        }

        // 回复删除
        function redel(id)
        {
           
            if (confirm('确定要删除吗?')) {
                var form = document.delform;
                form.action = '/admin/delReplay/'+id;
                form.submit();
            }
        }
    </script>


      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript" src='{{ asset("/js/jquery-1.8.3.min.js") }}'></script>
  <script>
   var td = $('#content');
    function fun(id) {
       if( $('#content').children().length > 0){
              
               $("#content").empty();
            
       }
       $('#rep').val(id);
        $.ajax({
          url:'/admin/replay',
          type:'get',
          async:false,
          data:{ 'commentId':id },
          dataType:'json',

          success:function(data)
          {
            console.log(data);
            // alert(data);
            //  console.log(data);
            if ( data.length >0 ) {

               for (var i = 0; i < data.length; i++) {
                // // alert(data[i].replayId);
                function getLocalTime(nS) {  
                     return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');  
                }
                var info = "<tr>";
                info += '<td>'+data[i].replayContent+'</td>';
                info += '<td>'+getLocalTime(data[i].replayTime)+'</td>';
                // info += '<td>'+data[i].replayTime+'</td>';
                info += '<td>'+data[i].replayer+'</td>';
                info += '<td><a href=javascript:redel('+data[i].replayId+');><button type="button"  class="btn btn-primary btn-xs">删除</button></a></td>';
                info += '</tr>';
                td.append(info);


              };

            }
          },
          error:function(){
            alert('ajax请求失败');
          }
        })

      }
      
</script>
</html>